package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsRegion;
import com.qf.service.AdminFegionService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;


@RequestMapping("/admin/region")
@CrossOrigin
@RestController
public class AdminRegionController {

    @Autowired
    private AdminFegionService adminFegionService;

    /**
     * 商场管理  行政区域列表
     * @param page
     * @param limit
     * @param name
     * @param code
     * @return
     */
    @GetMapping("/list")
    @RequiresPermissions("admin:region:list")
    @RequiresPermissionsDesc(menu = "商场管理，行政区域",button = "行政区域列表")
    public Object regionList(@RequestParam(defaultValue = "1")Integer page,
                             @RequestParam(defaultValue = "20")Integer limit,
                             String name,Integer code){

        IPage<DtsRegion> iPage = adminFegionService.selectRegionList(page,limit,name,code);

        long total = iPage.getTotal();
        List<DtsRegion> records = iPage.getRecords();

        DtsRegion[] items = new DtsRegion[records.size()];
        for (int i = 0; i < records.size(); i++) {
            items[i] = records.get(i);
        }

        HashMap<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", items);

        return ResponseUtil.ok(data);
    }

}
